package com.lnlyj.media.data;

import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;

import com.lnlyj.media.data.load.QueryConfig;

import java.util.Objects;

import static com.lnlyj.media.Constants.URI_MEDIA;

/**
 * wanglei 2020-04-16
 */
public class AlbumItem implements Parcelable {

    private QueryConfig config;
    private String name;
    private int count;
    private String icon;
    private long bucketId;
    private int iconId;

    public AlbumItem() {
    }

    protected AlbumItem(Parcel in) {
        config = in.readParcelable(QueryConfig.class.getClassLoader());
        name = in.readString();
        count = in.readInt();
        icon = in.readString();
        bucketId = in.readLong();
        iconId = in.readInt();
    }

    public static final Creator<AlbumItem> CREATOR = new Creator<AlbumItem>() {
        @Override
        public AlbumItem createFromParcel(Parcel in) {
            return new AlbumItem(in);
        }

        @Override
        public AlbumItem[] newArray(int size) {
            return new AlbumItem[size];
        }
    };

    public QueryConfig getConfig() {
        return config;
    }

    public void setConfig(QueryConfig config) {
        this.config = config;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public long getBucketId() {
        return bucketId;
    }

    public void setBucketId(long bucketId) {
        this.bucketId = bucketId;
    }

    public Uri getIconUri() {
        return Uri.withAppendedPath(URI_MEDIA, String.valueOf(iconId));
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        AlbumItem item = (AlbumItem) o;
        return count == item.count &&
                bucketId == item.bucketId &&
                iconId == item.iconId &&
                Objects.equals(config, item.config) &&
                Objects.equals(name, item.name) &&
                Objects.equals(icon, item.icon);
    }

    @Override
    public int hashCode() {
        return Objects.hash(config, name, count, icon, bucketId, iconId);
    }

    public void setIconId(int iconId) {
        this.iconId = iconId;
    }


    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel parcel, int i) {
        parcel.writeParcelable(config, i);
        parcel.writeString(name);
        parcel.writeInt(count);
        parcel.writeString(icon);
        parcel.writeLong(bucketId);
        parcel.writeInt(iconId);
    }
}
